import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.kafka_routes import router as kafka_router

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

# Create FastAPI app
app = FastAPI(
    title="Kafka FastAPI Demo",
    description="A FastAPI application demonstrating Kafka integration",
    version="1.0.0"
)

# Add CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Include routers
app.include_router(kafka_router)


@app.get("/")
async def root():
    return {
        "message": "Welcome to Kafka FastAPI Demo",
        "docs": "/docs",
        "kafka_endpoints": "/kafka"
    }


@app.get("/health")
async def health_check():
    return {"status": "healthy"}


if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)